<template>
<view>
<!--pages/topicality/xiaofeiquan/xiaofeiquan.wxml-->
<!--<import src="../../../webview/contact.wxml"></import>-->
<!-- <template is="inContact" data="{{showtk}}" /> -->
<view>
  <!--  -->
  <image src="http://imgbdb3.bendibao.com/xcx/20207/06/2020706100340_66046.png" class="main-img">
    <view class="city-box">
      <text>{{city}}</text>
      <!-- <image src="/images/dwicon.png"></image> -->
    </view>
    <view class="change-city">
      <text style="margin-left: 70rpx;">切换城市:</text>
      <picker @change="bindProv" :value="pindex" :range="provPick">
        <view class="sel-city">
          <view class="picker">
            <text>{{provPick[pindex]}}</text>
          </view>
          <image src="/static/images/dwicon.png"></image>
        </view>
      </picker>
      <picker @change="bindCity" :value="cindex" :range="cityPick">
        <view class="sel-city">
          <view class="picker">
            <text>{{cityPick[cindex]}}</text>
          </view>
          <image src="/static/images/dwicon.png"></image>
        </view>
      </picker>
    </view>
  </image>

  <view class="xfj-box" v-if="infoData.chengji">
    <view v-for="(item, index) in infoData.chengji" :key="index" class="xfj-content">
      <view class="xfj-item" v-if="item.stime">
        <view class="item-title">查询时间</view>
        <view class="item-text">{{item.stime}}</view>
      </view>
      <view class="xfj-item" v-if="item.method">
        <view class="item-title">查询方式</view>
        <view class="item-text">{{item.method}}</view>
      </view>
      <view class="xfj-item" v-if="item.rukou">
        <view class="item-title">查询入口</view>
        <view class="item-text" @tap="seeDetail" :data-id="item.id" :data-type="item.type" :data-citycode="item.citycode" :data-url="item.rukou" data-title="查询入口">
          <text style="color:#5195DD">查看详情</text>
        </view>
      </view>
      <view class="xfj-item" v-if="item.deal">
        <view class="item-title">操作方式</view>
        <view class="item-text" @tap="seeDetail" :data-id="item.did" :data-type="item.dtype" :data-citycode="item.citycode" :data-url="item.deal" data-title="操作方式">
          <text style="color:#5195DD">查看详情</text>
        </view>
      </view>
      <view class="xfj-item" v-if="item.tel">
        <view class="item-title">电话查询</view>
        <view class="item-text">{{item.tel}}</view>
      </view>
      <view class="xfj-item" v-if="item.url">
        <view class="item-title">成绩复核</view>
        <view class="item-text" @tap="seeDetail" :data-id="item.uid" :data-type="item.utype" :data-citycode="item.citycode" :data-url="item.url" data-title="成绩复核">{{item.desc}}
          <text style="color:#5195DD">查看详情</text> </view>
      </view>
    </view>
    <!-- 资讯 -->
    <view class="zx-box" v-if="articleData">
      <view class="zx-title">
        <image src="/static/images/sys/xf_icon2.png"></image>
        <text>高考资讯</text>
      </view>
      <view class="zx-content">
        <view v-for="(item, index) in articleData" :key="index" class="item-content" @tap="seeDetail" :data-id="item.id" :data-type="item.type" :data-citycode="citycode">
          <view class="zx-flex-row">
            <image class="doticon" src="/static/images/sys/doubledot.png"></image>
            <view class="zx-text">{{item.title}}</view>
          </view>
          <view class="timetext">{{item.publictime}}</view>
        </view>
      </view>
    </view>
  </view>

  <!-- 导粉 -->
  <view class="daofen" v-if="daofen">
    <rich-text :nodes="daofen.content" style="user-select:text;-webkit-user-select:text">
    </rich-text>
  </view>

</view>
<!-- 快捷导航 -->
<fastnav :qrcodeimg="qrcodeimg" :citycode="citycode" :showNav="showNav" :showShare="showShare"></fastnav>
</view>
</template>

<script>
// pages/topicality/xiaofeiquan/xiaofeiquan.js
//获取应用实例
const app = getApp();
const util = require("../../../../utils/util.js");
var QQMapWX = require("../../../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.min.js");
var qqmapsdk = new QQMapWX({
  key: 'KR7BZ-XSQ3P-VGFD7-LNRZL-E7PXE-STF76'
});
import fastnav from "../../../../component/fastnav/fastnav";

export default {
  data() {
    return {
      citycode: "hz",
      city: '杭州',
      province: '浙江',
      pindex: 0,
      cindex: 0,
      cityPick: ["选择城市"],
      newsData: [],
      showtk: false,
      showNav: true,
      // 快捷导航是否展开
      showShare: true // 显示分享按钮
      ,
      provPick: [],
      articleData: [],
      daofen: false,
      qrcodeimg: "",
      cityArray: "",
      citylist: "",
      infoData: "",
      title: ""
    };
  },

  components: {
    fastnav
  },
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    util.getUrl(app.globalData.url).then(res => {
      this.getProvinceData(options.city);
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: this.title ? this.title : "高考成绩查询"
    };
  },
  // 分享朋友圈
  onShareTimeline: function () {
    return {
      title: this.title ? this.title : "高考成绩查询",
      imageUrl: "http://imgbdb3.bendibao.com/xcx/20207/06/2020706100340_66046.png",
      query: {
        city: this.citycode
      }
    };
  },
  methods: {
    // 获取定位
    getLocation() {
      qqmapsdk.reverseGeocoder({
        success: res => {
          let city = res.result.address_component.city; // let city="芜湖市";

          let citydata = this.citylist.filter(v => {
            if (city.indexOf(v.cityname) != -1) {
              return v;
            }
          });

          if (citydata != '' && city.indexOf(this.city) == -1) {
            uni.showModal({
              content: '您当前定位城市为' + city + '\n是否需要切换到' + city + '高考成绩查询？',
              success: res => {
                if (res.confirm) {
                  this.setData({
                    city: Array.isArray(citydata) ? citydata[0].cityname : this.city,
                    citycode: Array.isArray(citydata) ? citydata[0].citycode : this.citycode,
                    province: Array.isArray(citydata) ? citydata[0].province : this.province,
                    cityPick: ["选择城市"]
                  });
                  let clist = [];
                  this.provPick.forEach((v, k) => {
                    if (v == this.province) {
                      this.setData({
                        pindex: k
                      });
                    }
                  });
                  this.cityArray[this.pindex].citylist.forEach(v => {
                    clist.push(v.cityname);
                  });
                  this.setData({
                    cityPick: this.cityPick.concat(clist)
                  });
                  this.cityPick.forEach((v, k) => {
                    if (v == this.city) {
                      this.setData({
                        cindex: k
                      });
                    }
                  }); // 获取城市公众号二维码

                  this.getQrcode(this.citycode);
                  this.getInfoData(this.citycode);
                  this.getzixunData(this.citycode);
                }
              }
            });
          }
        }
      });
    },

    // 获取城市公众号二维码
    getQrcode(citycode) {
      util.cityConfig(citycode).then(res => {
        this.setData({
          qrcodeimg: res.qrcode
        });
      });
    },

    // 获取城市
    getProvinceData(optcode) {
      let data = {
        action: "chengji",
        type: "city"
      };
      util.request('zhuanti.php', data).then(res => {
        this.setData({
          cityArray: res.data.data.city
        });
        let provPick = [];
        let citylist = [];
        let clist = [];
        this.cityArray.forEach(v => {
          v.citylist.forEach(v => {
            citylist.push(v);
          });
          provPick.push(v.province);
          this.setData({
            provPick,
            citylist
          });
        });

        if (this.citylist) {
          this.citylist.forEach((v, k) => {
            if (optcode == v.citycode) {
              this.setData({
                citycode: v.citycode,
                city: v.cityname,
                province: v.province
              });
            } else {
              this.setData({
                citycode: this.citycode,
                city: this.city,
                province: this.province
              });
            }
          });
        }

        this.provPick.forEach((v, k) => {
          if (v == this.province) {
            this.setData({
              pindex: k
            });
          }
        });
        this.cityArray[this.pindex].citylist.forEach(v => {
          clist.push(v.cityname);
        });
        this.setData({
          cityPick: this.cityPick.concat(clist)
        });
        this.cityPick.forEach((v, k) => {
          if (v == this.city) {
            this.setData({
              cindex: k
            });
          }
        }); // 获取城市公众号二维码

        this.getQrcode(this.citycode);
        this.getInfoData();
        this.getzixunData(this.citycode);

        if (this.citylist != "" && Array.isArray(this.citylist)) {
          // 获取定位
          this.getLocation();
        }
      });
    },

    // 获取内容
    getInfoData(citycode) {
      let data = {
        action: "chengji",
        // type: "city",
        citycode: citycode ? citycode : this.citycode
      };
      util.request('zhuanti.php', data).then(res => {
        if (res.data.data) {
          if (res.data.data.daofen != false) {
            res.data.data.daofen.content = res.data.data.daofen.content.replace(/<p([\s\w"=\/\.:;]+)((?:(="[^"]+")))/ig, '<p').replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p').replace(/<p([\s\w"=\/\.:;]+)((?:(class="[^"]+")))/ig, '<p').replace(/<p>/ig, '<p class="p_class">').replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1').replace(/<img/gi, '<img style="width:100%;height:auto"'); // .replace(/<span>/ig, '<p class="p_class">')
          }
        }

        uni.setNavigationBarTitle({
          title: res.data.data ? res.data.data.title : "高考成绩查询"
        });
        this.setData({
          infoData: res.data.data,
          daofen: res.data.data.daofen,
          title: res.data.data.title
        });
      });
    },

    // 获取资讯
    getzixunData(citycode) {
      util.inforMation(citycode, "高考").then(res => {
        this.setData({
          articleData: res
        });
      });
    },

    // 省份选择
    bindProv: function (e) {
      this.setData({
        pindex: e.detail.value,
        cindex: 0,
        cityPick: ["选择城市"]
      });
      let clist = [];
      this.cityArray[this.pindex].citylist.forEach(v => {
        clist.push(v.cityname);
      });
      this.setData({
        cityPick: this.cityPick.concat(clist)
      });
    },

    // 城市选择
    bindCity(e) {
      this.setData({
        cindex: e.detail.value
      });
      let cityname = this.cityPick[this.cindex];

      if (this.citylist) {
        this.citylist.forEach(v => {
          if (v.cityname == cityname) {
            let citycode = v.citycode;
            this.setData({
              citycode,
              city: cityname
            });
          }
        });
      } // 获取城市公众号二维码


      this.getQrcode(this.citycode);
      this.getInfoData(this.citycode);
      this.getzixunData(this.citycode);
    },

    // 查看详情点击事件
    seeDetail(e) {
      let id = e.currentTarget.dataset.id;
      let citycode = e.currentTarget.dataset.citycode;
      let url = e.currentTarget.dataset.url;
      let type = e.currentTarget.dataset.type;
      let title = e.currentTarget.dataset.title;

      if (id != 0) {
        uni.navigateTo({
          url: '/pages/article/detail/detail?id=' + id + '&type=' + type + '&city=' + citycode
        });
      } else {
        this.setData({
          showtk: true
        });
        util.navContact(title, url);
      }
    },

    // 进入客服会话
    contact() {
      this.setData({
        showtk: false
      });
    },

    // 关闭
    close() {
      this.setData({
        showtk: false
      });
    },

    /**
     * 页面滑动事件的处理函数
     */
    onPageScroll: function (e) {
      this.setData({
        showNav: false
      });
    }
  }
};
</script>
<style>
/* pages/topicality/xiaofeiquan/xiaofeiquan.wxss */
.main-img{width: 100%;height: 276rpx;}
.city-box{background: #ffffff;border-radius: 35rpx;padding: 10rpx 30rpx;position: absolute;
top: 40rpx;right: 30rpx;display: flex;align-items: center;}
.city-box text{font-size: 30rpx;font-weight: bolder;}
.city-box image{width: 23rpx;height: 15rpx;margin-left: 10rpx;}
.change-city{background:rgba(255,255,255,1);box-shadow:0rpx 6rpx 6rpx rgba(0,0,0,0.16);
opacity:1;border-radius:20rpx;padding:30rpx 0rpx;position: absolute;top:235rpx;width: 90%;
margin-left: 36rpx;display: flex;align-items: center;}
.change-city text{font-size:28rpx;font-family:PingFang SC;font-weight:bold;line-height:36rpx;
color:rgba(20,20,20,1);opacity:1;width: 102rpx;text-align: center;white-space:nowrap;}
.sel-city{display: flex;align-items: center;margin-left: 80rpx;}
.sel-city image{width: 19rpx;height: 10rpx;margin-left: 15rpx}

.xfj-box{margin: 100rpx 36rpx;}
.xfj{margin: 20rpx 0;}
.xfj view{user-select:text;-webkit-user-select:text}
.xfj-title{display: flex;align-items: center;flex-direction: row;}
.xfj-title image{width: 18rpx;height: 26rpx;margin-right: 15rpx;}
.xfj-title text{font-size:32rpx;font-family:PingFang SC;font-weight:bold;
line-height:44rpx;color:rgba(20,20,20,1);opacity:1;}

.xfj-content{background:rgba(242,244,252,1);opacity:1;border-radius:20rpx;padding: 40rpx 36rpx;
  margin-top: 34rpx;}
.xfj-content:nth-of-type(n+4){display: none;}
.xfj-content1{background:rgba(242,244,252,1);opacity:1;border-radius:20rpx;padding: 40rpx 36rpx;
  margin-top: 34rpx;}
.xfj-item{display: flex;align-items: flex-start;flex-direction: row;margin-bottom: 32rpx;}
.item-title{font-size:26rpx;font-family:PingFang SC;font-weight:bold;
line-height:36rpx;color:rgba(20,20,20,1);opacity:1;white-space:nowrap; margin-right: 38rpx;}
.item-text{border-bottom:1rpx solid rgba(236,236,236,1);opacity:1;padding-bottom: 26rpx;
font-size:26rpx;font-family:PingFang SC;font-weight:500;line-height:36rpx;color:rgba(90,90,90,1);flex: 1;
word-break:break-all;display: -webkit-box;white-space: pre-wrap;}

.xfj-btn{display: flex;flex-direction: row;align-items: center;justify-content:center;}
.xfj-btn-box{background:#D9E6F8;border-radius:38rpx;display: flex;flex-direction: row;align-items: center;
padding: 15rpx 25rpx;}
.img1{width: 25rpx;height: 25rpx;margin-right: 8rpx;}
.img{width: 20rpx;height: 25rpx;margin-right: 8rpx;}
.xfj-btn-box text{font-size:26rpx;font-family:PingFang SC;font-weight:bold;
line-height:36rpx;color:rgba(81,149,221,1);opacity:1;white-space:nowrap;}

/* 内容 */
.tips-box{margin-top: 30rpx;}
.tips{background-color: #F2F4FC;border-radius: 20rpx;padding: 30rpx;display: flex;flex-direction: row;
align-items: flex-start;margin-bottom: 30rpx;}
.tips:nth-of-type(n+3){display: none}
.tips image{width: 32rpx;height: 32rpx;margin-right: 30rpx;}
.tips text{color: #5195DD;font-size:28rpx;font-weight: 500;}
.tips1{background-color: #F2F4FC;border-radius: 20rpx;padding: 30rpx;display: flex;flex-direction: row;align-items: flex-start;margin-bottom: 30rpx;}
.tips1 image{width: 32rpx;height: 32rpx;margin-right: 30rpx;}
.tips1 text{color: #5195DD;font-size:28rpx;font-weight: 500;}

.content-box{background-color: #F2F4FC;border-radius: 20rpx;}
.cont-title{display: flex;align-items: center;justify-content: space-between;}
.wcont-box{padding: 30rpx;}
.yyplatform{border-bottom: 1rpx solid #bbb;padding-bottom: 30rpx;margin-bottom: 30rpx;}
.yyplatform:nth-of-type(n+3){display: none}
.yyplatform1{border-bottom: 1rpx solid #bbb;padding-bottom: 30rpx;margin-bottom: 30rpx;}
.wcont{display: flex;align-items: flex-start ;justify-content: space-between;margin-bottom: 30rpx;}
.wcont text{font-size: 28rpx;color: #000;font-weight: 500; white-space:nowrap;}
.wcont view{font-size: 28rpx;color: #000;font-weight: 500; margin-left: 70rpx;}
.yuyueBtn{background-color: #61a3e9;text-align: center;border-radius: 40rpx;width: 100%;padding: 20rpx 0;
font-size: 28rpx;color: #fff;font-weight: 500; }
.tapbtn{display: flex;align-items: center;justify-content: space-between;margin-top: 30rpx;}
.yybtn{background-color: #DAE6F8;border-radius: 38rpx;padding: 20rpx 40rpx;display: flex;align-items: center;}
.yybtn image{width: 23rpx;height: 24rpx;margin-right: 15rpx;}
.yybtn text{font-size:26rpx;font-family:PingFang SC;font-weight:500;
color:rgba(81,149,221,1);opacity:1;}

.palce-title{display: flex;align-items: center;justify-content: center;flex-direction: row;margin: 30rpx 0;}
.hline{width: 20%;border: 1rpx solid #5A5A5A;}
.palce-title text{font-size:28rpx;font-family:PingFang SC;margin: 0 40rpx;
font-weight:500;color:rgba(20,20,20,1);opacity:1;}


.wtitle1{border-radius:20rpx 0 0 0;background-color: #5195DD;font-size: 28rpx;color: #fff;
  padding: 30rpx 0; width: 230rpx;text-align: center;}
.wtitle2{border-radius:20rpx 0 0 0;background-color: #F2F4FC;font-size: 28rpx;color: #000;
  padding: 30rpx 0; width: 230rpx;text-align: center;}
.dtitle1{background-color: #5195DD;font-size: 28rpx;color: #fff;
  padding: 30rpx 0; width: 230rpx;text-align: center;}
.dtitle2{background-color: #F2F4FC;font-size: 28rpx;color: #000;
  padding: 30rpx 0; width: 230rpx;text-align: center;}
.xtitle1{border-radius:0 20rpx 0 0;background-color: #5195DD;font-size: 28rpx;color: #fff;
  padding: 30rpx 0; width: 230rpx;text-align: center;}
.xtitle2{border-radius:0 20rpx 0 0;background-color: #F2F4FC;font-size: 28rpx;color: #000;
  padding: 30rpx 0; width: 230rpx;text-align: center;}
/* 查看更多 */
.see-more{display: flex;justify-content: center;margin: 30rpx 0;}
.see-more view{background-color: #EEEEEE;padding: 20rpx 40rpx;font-size:26rpx;border-radius:12rpx;
font-family:PingFang SC;font-weight:600;color: #141414;text-align: center;width: 200rpx;white-space:nowrap;}

/* 资讯 */
.zx-box{margin: 30rpx 0rpx;}
.zx-title{display: flex;align-items: center;flex-direction: row;}
.zx-title image{width: 18rpx;height: 26rpx;margin-right: 15rpx;}
.zx-title text{font-size:32rpx;font-family:PingFang SC;font-weight:bold;
line-height:44rpx;color:rgba(20,20,20,1);opacity:1;}
.zx-text{font-size: 30rpx;color: #000000;font-weight:bold;}
/*white-space:nowrap;  */
.zx-flex-row{display: flex;align-items: flex-start;}
.doticon{width: 24rpx;height: 16rpx;margin-right: 15rpx;margin-top: 10rpx;}
.item-content{display: flex;flex-direction: column;border-bottom: 1rpx solid #cccccc;
padding: 30rpx 0;}
.timetext{font-size:26rpx;font-family:PingFang SC;font-weight:500;
color:rgba(152,150,150,1);opacity:1;margin-top: 20rpx;margin-left: 40rpx;}

/* 导粉 */
.daofen{margin:0 30rpx 80rpx 30rpx;text-align: center;}
.p_class{margin:10rpx 30rpx;line-height: 50rpx;}
</style>